package org.jetlinks.demo.protocol.siterwell.tcp.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Optional;

@Getter
@AllArgsConstructor
public enum DeviceType {

    EMPTY("空设备", "00"),
    REMOTE_CONTROL("遥控", "01"),
    DOOR_MAGNETISM("门磁", "02"),
    INFRA_RED("红外", "03"),
    SMOKE_SENSATION("烟感", "04"),
    GAS("燃气", "05"),
    WATER_IMMERSION("水浸", "06"),
    CO("CO", "09"),
    GATEWAY("网关", "0a"),
    TEMPERATURE_SENSOR("温感", "0c"),
    ELECTRICAL("电气", "10"),
    PRESSURE("压力", "11"),
    ON_OFF("开关", "12"),
    WATER_LEVEL("水位", "13"),
    AKR("AKR", "20");


    private String desc;
    private String code;

    @Override
    public String toString() {
        return "{" +
                "desc = " + desc +
                " , code = " + code +
                "}";
    }

    public static Optional<DeviceType> of(String typeCode) {
        DeviceType[] deviceTypes = values();
        String lowerCaseTypeCode = typeCode.toLowerCase();
        int len = deviceTypes.length;
        for (int i = 0; i < len; i++) {
            DeviceType curDeviceType = deviceTypes[i];
            if (curDeviceType.getCode().equals(lowerCaseTypeCode)) {
                return Optional.of(curDeviceType);
            }
        }
        return Optional.empty();
    }

}
